package mars;

public class Position {
	private int x;
	private int y;
	private Heading heading;
	
	Position(int x, int y, Heading heading) {
		this.x = x;
		this.y = y;
		this.heading = heading;
	}
	
	Position(int x, int y) {
		this.x = x;
		this.y = y;
		heading = Heading.N;
	}
	
	public boolean isBelowPosition(Position p2) {
		if(this.x <= p2.x && this.y <= p2.y) {
			return true;
		}
		return false;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Heading getHeading() {
		return heading;
	}

	public void setHeading(Heading heading) {
		this.heading = heading;
	}
	
	public String toString() {
		return x+" "+y+" "+heading.toString();
	}
	
	public enum Heading {
		N("N", 1), E("E", 2), S("S", 3), W("W", 4);
		private String headingName;
		private int headingAngle;
		Heading(String headingName, int headingAngle) {
			this.headingName = headingName;
			this.headingAngle = headingAngle;
		}
		
		public int getHeadingAngle() {
			return this.headingAngle;
		}
		
		public Heading getHeadingFromAngle(int headingAngle) throws ParseException {
			for(Heading heading : Heading.values()) {
				if(heading.getHeadingAngle() == headingAngle) {
					return heading;
				}
			}
			throw new ParseException("Heading angle is incorrect. "+headingAngle);
		}
		
		public String toString() {
			return this.headingName;
		}
	}; 
}
